<?php

namespace  console\controllers;
use yii\console\Controller;
use console\models\MainModel;

class MainController extends Controller
{
    public $APPID =  null;
    /**
     * 同步所有数据
     */
    public function actionSync($appid='')
    {
        return (new MainModel())->actionSyncAll($appid);
    }
    /**
     * 同步用户分析报告
     */
    public function actionUser($appid='')
    {

        $appid = !empty($appid) ? $appid : $this->init();
        $result =  (new MainModel())->actionUser($appid);
        if (!$result) {
            echo 102;
        } else {
            echo 200;
        }
    }

    /**
     * 同步图文分析报告
     */
    public function actionArticle($appid='')
    {
        $appid = !empty($appid) ? $appid : $this->init();

        $result = (new MainModel())->actionArticle($appid);

        if (!$result) {
            echo 102;
        } else {
            echo 200;
        }
    }

    public function actionMsg($appid='')
    {
        $appid = !empty($appid) ? $appid : $this->init();
        $result = (new MainModel())->actionMsg($appid);

        if (!$result) {
            echo 102;
        } else {
            echo 200;
        }
    }

    public function actionClear($appid='')
    {
        $appid = !empty($appid) ? $appid : $this->init();
        $result = (new MainModel())->actionClearQuota($appid);

        if (!$result) {
            echo 102;
        } else {
            echo 200;
        }
    }

    public function actionComponent()
    {
        $result = (new MainModel())->actionClearComponent();

        if (!$result) {
            echo 102;
        } else {
            echo 200;
        }
    }
    public function init()
    {
        $this->APPID = isset(\Yii::$app->params['appid']) && !empty(\Yii::$app->params['appid']) ? \Yii::$app->params['appid'] : 'wx2c076b140ffffb59';
        return $this->APPID;
    }
}